/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.scene.service;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.common.utils.IdGen;
import com.lczyfz.istep.modules.scene.dao.SceneRouterDao;
import com.lczyfz.istep.modules.scene.entity.*;
import com.lczyfz.istep.modules.sys.entity.User;
import com.lczyfz.istep.modules.sys.utils.UserUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * 路由管理Service
 * @author dh
 * @version 2017-03-20
 */
@Service
@Transactional(readOnly = true)
public class SceneRouterService extends CrudService<SceneRouterDao, SceneRouter> {

	public SceneRouter get(String id) {
		return super.get(id);
	}
	
	public List<SceneRouter> findList(SceneRouter sceneRouter) {
		return super.findList(sceneRouter);
	}
	
	public Page<SceneRouter> findPage(Page<SceneRouter> page, SceneRouter sceneRouter) {
		return super.findPage(page, sceneRouter);
	}
	
	@Transactional(readOnly = false)
	public void save(SceneRouter sceneRouter) {
		super.save(sceneRouter);
	}
	
	@Transactional(readOnly = false)
	public void delete(SceneRouter sceneRouter) {
		super.delete(sceneRouter);
	}

	public  List<SceneRouter>  getRouterByName(SceneRouter sceneRouter)
	{
		return dao.getRouterByName(sceneRouter);
	}

	@Transactional(readOnly = false)
	public void insert(SceneRouter sceneRouter) {
		dao.insert(sceneRouter);
	}
	public  List<SceneSubnet>  getSubnetList(SceneRouter sceneRouter)
	{
		return dao.getSubnetList(sceneRouter);
	}
	@Transactional(readOnly = false)
	public void saveInterface(String routerId,String subnetId) {

		dao.saveInterface(routerId,subnetId);
	}

	/**
	 * 删除路由接口
	 * @param subnetId
	 * @param routerId
	 */
	@Transactional(readOnly = false)
	public void deleteInterface(String subnetId, String routerId)
	{
		dao.deleteInterface(subnetId, routerId);
	}
	@Transactional(readOnly = false)
	public void removeGateWay(SceneRouter sceneRouter)
	{
		dao.removeGateWay(sceneRouter);
	}
	public void preInsert(SceneRouter info) {

		User user = UserUtils.getUser();
		if (StringUtils.isNotBlank(user.getId())) {
			info.setUpdateBy(user);
			info.setCreateBy(user);
		}
		Date date=new Date();
		info.setUpdateDate(date);
		info.setCreateDate(date);

	}
	public List<SceneRouter> findRouterListByEnvironmentId(String DEL_FLAG_NORMAL,String id)
	{
		return dao.findRouterListByEnvironmentId(DEL_FLAG_NORMAL,id);
	}
	public List<SceneRouter> findCtfRouterListByEnvironmentId(SceneCtfEnvironment sceneCtfEnvironment)
	{
		return dao.findCtfRouterListByEnvironmentId(sceneCtfEnvironment);
	}
	public List<SceneRouterTable> findRouterTableListByRouterId(String routerId)
	{
		return dao.findRouterTableListByRouterId(routerId);
	}
	public List<SceneFirewall> findFirewallListByEnvironmentId(String environmentId)
	{
		return dao.findFirewallListByEnvironmentId(environmentId);
	}

	@Transactional(readOnly = false)
	public void firewallInsert(SceneFirewall sceneFirewall)
	{
		dao.firewallInsert(sceneFirewall);
	}

	@Transactional(readOnly = false)
	public void routerTableSave(SceneRouterTable sceneRouterTable)
	{
		dao.routerTableSave(sceneRouterTable);
	}
	public SceneFirewall getRouterFirewall(String routerId)
	{
		return dao.getRouterFirewall(routerId);
	}
	@Transactional(readOnly = false)
	public void routerFirewallInsert(String firewallId,String routerId)
	{
		dao.routerFirewallInsert(firewallId,routerId);
	}
	@Transactional(readOnly = false)
	public void firewallSave(SceneFirewall sceneFirewall,String routerId)
	{
		String firewallId=IdGen.uuid();
		sceneFirewall.setId(firewallId);
		dao.firewallInsert(sceneFirewall);
		logger.debug("dingh===firewallId= [{}] [{}]", sceneFirewall.getId(), routerId);
		dao.routerFirewallInsert(firewallId,routerId);

	}

	public List<SceneFirewallRule> findFirewallRuleList(String firewallId)
	{
		return dao.findFirewallRuleList(firewallId);
	}
	@Transactional(readOnly = false)
	public void firewallRuleSave(SceneFirewallRule sceneFirewallRule)
	{
		String firewallRuleId=IdGen.uuid();
		sceneFirewallRule.setId(firewallRuleId);
		dao.firewallRuleInsert(sceneFirewallRule);
	}
	public SceneFirewall getFirewallById(String firewallId)
	{
		return dao.getFirewallById(firewallId);
	}
	@Transactional(readOnly = false)
	public void routerPortSave(String routerId,String portId,String ip)
	{
		dao.routerPortSave(routerId,portId,ip);
	}

	@Transactional(readOnly = false)
	public void deleteRouterTable(String routerId)
	{
		dao.deleteRouterTable(routerId);
	}
	@Transactional(readOnly = false)
	public void deleteRouterFirewall(String routerId)
	{
		dao.deleteRouterFirewall(routerId);
	}
	@Transactional(readOnly = false)
	public void deleteFirewall(String firewallId)
	{
		dao.deleteFirewall(firewallId);
	}
	@Transactional(readOnly = false)
	public void deleteFirewallRule(String firewallId)
	{
		dao.deleteFirewallRule(firewallId);
	}
	@Transactional(readOnly = false)
	public void deleteRouterPort(String routerId)
	{
		dao.deleteRouterPort(routerId);
	}



}